const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

let src = path.resolve(__dirname, 'src');
/**
 * 解决引入vue时，和标签引入不同导致的问题。
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        }
    },
 */
module.exports = {
    entry: `${src}/main.js`,
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new HtmlWebpackPlugin({
            hash: true,
            filename: 'index.html',
            template: `${src}/index.html`
        }),
        new VueLoaderPlugin(),
    ],
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader', 
                    'css-loader'
                ]
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader', 
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader', 
                    'css-loader',
                    'sass-loader'
                ]
            },
            {
                test: /\.(jpg|jpeg|png|bmp)$/,
                use: [
                    'url-loader?limit=0&name=[hash:8]_[name].[ext]',
                ]
            },
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.vue$/,
                use: 'vue-loader'
            },
            {
                test:/\.(ttf|eot|svg|woff|woff2|otf)$/, 
                use: 'url-loader'
            }
        ]
    },
    devServer: {
        open: true,                                 // 自动打开浏览器
        contentBase: path.join(__dirname, 'dist'),
        compress: true,
        //host: '192.168.2.198',
        host: '127.0.0.1',
        port: 8888
    }
}